package com.example.myapplication.utils

import com.example.myapplication.App.Companion.context
import com.example.myapplication.BuildConfig
import io.jsonwebtoken.Jwts
import io.jsonwebtoken.SignatureAlgorithm
import java.nio.charset.StandardCharsets
import kotlin.text.toByteArray
import kotlin.to


/**
 * @Description:
 */
object DigitalUtil {

    fun generateJWT(path: String): String {
        val key = "71283b1b80a5449d961fbb375017aebb".toByteArray(StandardCharsets.UTF_8)

        val header = mapOf<String, String>(
            "alg" to "HS256",
            "typ" to "JWT",
        )
        val payload = mapOf<String, String>(
            "bundle" to context.packageName,
            "ver" to BuildConfig.VERSION_NAME,
            "ip" to IPUtils.getPublicIPAddress(),
            "url" to path,
            "ts" to System.currentTimeMillis().toString()
        )
        return Jwts.builder()
            .setHeader(header)
            .setClaims(payload)
            .signWith(SignatureAlgorithm.HS256, key)
            .compact()
    }
}